package com.example.common;

import lombok.Data;

@Data
public class Result {
    private static final String SUCCESS_CODE = "200";
    private static final String ERROR_CODE = "500";
    private static final String SUCCESS_MSG = "操作成功";
    private static final String ERROR_MSG =  "操作失败";
    private static final String WARNING_CODE = "300";

    private String code;
    private String msg;
    private Object data;
    private String token;

    public static Result success(){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setMsg(SUCCESS_MSG);
        return result;
    }

    public static Result success(String msg){
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(SUCCESS_CODE);
        return result;
    }

    public static Result success(Object data){
        Result result = success();
        result.setData(data);
        return result;
    }


    public static Result success(Object data, String token){
        Result result = success(data);
        result.setToken(token);
        return result;
    }

    public static Result success( String msg,Object data){
        Result result = success(data);
        result.setMsg(msg);
        return result;
    }

    public static  Result warning(String msg){
        Result result = new Result();
        result.setCode(WARNING_CODE);
        result.setMsg(msg);
        return result;
    }

    public static Result error(String msg){
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(ERROR_CODE);
        return result;
    }

    public static Result error(){
        Result result = new Result();
        result.setCode(ERROR_CODE);
        result.setMsg(ERROR_MSG);
        return result;
    }


}
